import 'package:enterprise_v6_app/app/components/toast_widget.dart';
import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/common/simple_choice_bean.dart';
import 'package:enterprise_v6_app/app/data/entities/alarm/all_alarm_records_entity.dart';
import 'package:get/get.dart';

class DisposalPageController extends GetxController {

  AllAlarmRecordsEntity item = Get.arguments as AllAlarmRecordsEntity;

  /// 处置方式选择
  List<SimpleChoiceBean> choiceDataList = [
    SimpleChoiceBean(id: '0', name: '消警'),
    SimpleChoiceBean(id: '1', name: '处置'),
  ];

  /// 处置方式
  SimpleChoiceBean? choiceBean;


  /// 消警措施
  List<String> disPhotos = [];

  /// 消警描述
  String? disDesc;

  /// 附件
  List<String> uploadedFiles = [];

  /// 是否存在隐患切换
  void switchStates(SimpleChoiceBean bean) {
    choiceBean = bean;
    update();
  }

  /// 处置-消警报警记录
  disposeAlarmRecord() async {
    if(choiceBean == null) {
      AppToast.show('请选择处置方式');
      return;
    }
    if(disDesc == null || disDesc == '') {
      AppToast.show('请输入消警描述');
      return;
    }

    final data = {
      'disposalControl': disPhotos.join(','), // 消警/处置措施
      'disposalDesc': disDesc, // 消警/处置描述
      'disposalType': choiceBean?.id, //0，消警；1，处置
      'filePath': uploadedFiles,  // 附件
      'id': item.id, // 报警记录id
    };

    final res = await HttpUtil().generatePostRequest(Interface.disposeAlarmRecord, data: data).execute();

    res.onSuccess((result) {
      Get.back();
      Get.back();
      AppToast.show('处置成功');
    });
  }
}
